package com.cytech.cloudclinic.adapter;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.bean.Acupoint;
import com.cytech.cloudclinic.bean.Drug;

import java.util.List;

import static com.cytech.cloudclinic.app.Constant.DRUG_TAG_1;
import static com.cytech.cloudclinic.app.Constant.DRUG_TAG_2;
import static com.cytech.cloudclinic.app.Constant.DRUG_TAG_3;
import static com.cytech.cloudclinic.app.Constant.DRUG_TAG_4;
import static com.cytech.cloudclinic.app.Constant.DRUG_TAG_5;
import static com.cytech.cloudclinic.app.Constant.DRUG_TAG_6;

public class PrescriptionChildAdapter extends BaseQuickAdapter<Drug, BaseViewHolder> {

    private int currentPos = 0;
    private boolean isShowPoint = false;
    private int parentDrugId;

    public PrescriptionChildAdapter(List<Drug> data,boolean isShowPoint,int parentDrugId) {
        super(R.layout.item_prescription_drug_child, data);
        this.isShowPoint = isShowPoint;
        this.parentDrugId = parentDrugId;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Drug s) {
        LinearLayout llDrugInfo1 = baseViewHolder.getView(R.id.ll_item_drug_info);
        LinearLayout llDrugInfo2 = baseViewHolder.getView(R.id.ll_item_drug_info_2);

        //穴位总布局
        LinearLayout acupointLayout = baseViewHolder.getView(R.id.ll_prescription_acupoint);
        //穴位体位
        LinearLayout bodyPointLayout = baseViewHolder.getView(R.id.ll_item_acupoint_body);
        //穴位时间
        LinearLayout acupointTimeLayout = baseViewHolder.getView(R.id.ll_item_acupoint_time);


        TextView drugName = baseViewHolder.getView(R.id.tv_prescription_child_drug_name);
        drugName.setText(s.drug_name);
        baseViewHolder.setText(R.id.tv_prescription_child_drug_weight,String.valueOf(s.number));
        baseViewHolder.setText(R.id.mtv_prescription_child_min_unit,s.subunit);
        if(parentDrugId == DRUG_TAG_1){
            baseViewHolder.setVisible(R.id.tv_prescription_child_drug_usage,false);
            llDrugInfo1.setVisibility(View.VISIBLE);
            llDrugInfo2.setVisibility(View.GONE);
            bodyPointLayout.setVisibility(View.GONE);
            acupointTimeLayout.setVisibility(View.VISIBLE);
            acupointLayout.setVisibility(View.VISIBLE);
        }else if(parentDrugId == DRUG_TAG_2){
            baseViewHolder.setText(R.id.tv_prescription_child_drug_name2,s.drug_name);
            if(s.numbers!=null&&s.numbers.size()>2){
                baseViewHolder.setText(R.id.tv_prescription_child_drug_min_unit1,String.valueOf(s.numbers.get(0)));
                baseViewHolder.setText(R.id.tv_prescription_child_drug_min_unit2,String.valueOf(s.numbers.get(1)));
                baseViewHolder.setText(R.id.tv_prescription_child_drug_min_unit3,String.valueOf(s.numbers.get(2)));

            }
            llDrugInfo1.setVisibility(View.GONE);
            llDrugInfo2.setVisibility(View.VISIBLE);
            acupointLayout.setVisibility(View.GONE);
        }else if(parentDrugId == DRUG_TAG_3){
            baseViewHolder.setText(R.id.tv_prescription_child_drug_usage,s.usage_mode);
            llDrugInfo1.setVisibility(View.VISIBLE);
            llDrugInfo2.setVisibility(View.GONE);
            acupointLayout.setVisibility(View.GONE);
        }else if(parentDrugId == DRUG_TAG_4){
            baseViewHolder.setVisible(R.id.tv_prescription_child_drug_usage,false);
            llDrugInfo1.setVisibility(View.VISIBLE);
            llDrugInfo2.setVisibility(View.GONE);
            acupointLayout.setVisibility(View.GONE);
        }else if(parentDrugId == DRUG_TAG_5){
            baseViewHolder.setText(R.id.tv_acupoint_body_point,s.bodyPoint);
            baseViewHolder.setText(R.id.tv_acupoint_body_times,String.valueOf(s.bodyPointTimes));
            llDrugInfo1.setVisibility(View.VISIBLE);
            llDrugInfo2.setVisibility(View.GONE);
            //理疗项目只显示药品名称
            baseViewHolder.setVisible(R.id.tv_prescription_child_drug_usage,false);
            baseViewHolder.setVisible(R.id.tv_prescription_child_drug_weight,false);
            baseViewHolder.setVisible(R.id.mtv_prescription_child_min_unit,false);
            bodyPointLayout.setVisibility(View.VISIBLE);
            acupointTimeLayout.setVisibility(View.GONE);
            acupointLayout.setVisibility(View.VISIBLE);
        }else if(parentDrugId == DRUG_TAG_6){
            llDrugInfo1.setVisibility(View.VISIBLE);
            llDrugInfo2.setVisibility(View.GONE);
            acupointLayout.setVisibility(View.GONE);
            baseViewHolder.setVisible(R.id.tv_prescription_child_drug_usage,false);
        }else{
            acupointLayout.setVisibility(View.GONE);
        }


        if(s.acupoints!=null){
            baseViewHolder.setText(R.id.tv_acupoint_time,s.acupoints.acupoint_time);
            baseViewHolder.setText(R.id.tv_acupoint_num,String.valueOf(s.acupoints.acupoint_number));
        }
        baseViewHolder.setText(R.id.tv_item_acupoint_name,s.acupoints.acupoint_name);
    }

    public void setCurrentPos(int currentPos) {
        this.currentPos = currentPos;
        notifyDataSetChanged();
    }

}
